< previous page page_148 next page >

Page 148
Public Constants
The most common type of constants youll create are public in scope. The reason is that constants are normally used throughout your entire application. To declare a public constant, use code that looks similar to the following:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Const gconERR_MSG As String = "This value is in Error"
You can now use this public constant, gconERR_MSG, in any procedure in your entire application.
EXERCISE
Global Constant Example
1. Look in the Vars.bas file to view the aforementioned declaration.
2. Double-click the Global Const command button to view the following code, which uses the public constant:
Private Sub cmdConst_Click ()
lblConst.Caption = gconERR_MSG
End Sub
analysis.gifGlobal constants are the ones you will use most often. These are easy to use all over your application and easy to change.

Built-in Constants
Visual Basic has many other built-in constants that youll learn about as you use more of the built-in functions in Visual Basic. Many of the custom controls and DLLs youll use also have their set of built-in constants. Most of the Visual Basic constants start with the prefix vb. Other DLLs have their own prefixes.
Mathematical and Relational Operators
Any programming language has a set of symbols that allow you to perform a mathematical or relational operation on two or more operands. These symbols are called mathematical and relational operators. Visual Basic has a rich set of these operators. Here are some examples:

 
< previous page page_148 next page >

If you like this book, buy it!